Imports System
Imports DotNetNuke
Imports DotNetNuke.Security
Imports DotNetNuke.Security.Permissions
Imports DotNetNuke.Services.Mail
Imports Microsoft.VisualBasic.Constants
Imports System.Globalization
Imports System.Text
Imports System.Collections

Namespace RTP.HTMLNewsletter



#Region "NewsletterController Class "
    Public Class NewsletterController
        Implements DotNetNuke.Entities.Modules.IUpgradeable

        Public Function UpgradeModule(ByVal Version As String) As String Implements Entities.Modules.IUpgradeable.UpgradeModule
            Dim rtnMessage As String = "Newsletter Upgrade successful - " & Version
            InstallSchedule()
            Try
            Catch ex As Exception
                DotNetNuke.Services.Exceptions.LogException(ex)

                Return "Newsletter Upgrade - Exception: " & Version & " - Message: " & ex.Message.ToString
            End Try
            Return rtnMessage
        End Function
        Public Sub InstallSchedule()
            Dim objScheduleItem As New DotNetNuke.Services.Scheduling.ScheduleItem
            objScheduleItem = DotNetNuke.Services.Scheduling.SchedulingProvider.Instance().GetSchedule("RTP.HTMLNewsletter.NewsletterSchedule, RTP.HTMLNewsletter", Nothing)
            If objScheduleItem Is Nothing Then
                objScheduleItem = New DotNetNuke.Services.Scheduling.ScheduleItem
                objScheduleItem.TypeFullName = "RTP.HTMLNewsletter.NewsletterSchedule, RTP.HTMLNewsletter"
                objScheduleItem.TimeLapse = 1
                objScheduleItem.TimeLapseMeasurement = "m"
                objScheduleItem.RetryTimeLapse = 5
                objScheduleItem.RetryTimeLapseMeasurement = "m"
                objScheduleItem.RetainHistoryNum = 10
                objScheduleItem.Enabled = True
                objScheduleItem.ObjectDependencies = ""
                objScheduleItem.FriendlyName = "HTML Newsletter"
                DotNetNuke.Services.Scheduling.SchedulingProvider.Instance().AddSchedule(objScheduleItem)
            End If
        End Sub



        Public Function GetNewslettersByUserID(ByVal UserID As Integer, ByVal PortalID As Integer, ByVal AdminUser As Boolean) As ArrayList
            Return CBO.FillCollection(DataProvider.Instance().GetNewslettersByUserID(UserID, PortalID, AdminUser), GetType(NewsletterInfo))
        End Function
        Public Function GetNewsletterbyID(ByVal ItemID As Integer) As NewsletterInfo
            Return CType(CBO.FillObject(DataProvider.Instance().GetNewsletterById(ItemID), GetType(NewsletterInfo)), NewsletterInfo)
        End Function
        Public Function GetNewslettersForEdit(ByVal ModuleID As Integer) As ArrayList
            Return CBO.FillCollection(DataProvider.Instance().GetNewslettersForEdit(ModuleID), GetType(NewsletterInfo))
        End Function
        Public Function AddNewsletter(ByVal NLSummary As String, ByVal NLBody As String, ByVal NLDesc As String, ByVal NLAttachment As String, ByVal NLRoleSent As Integer, _
                                      ByVal NLUserID As Integer, ByVal NLEmail As String, ByVal ModuleID As Integer, ByVal ArticleID As Integer, ByVal ArticleTabModuleID As Integer, _
                                      ByVal Published As Boolean, ByVal PublishDate As DateTime, ByVal PortalID As Integer) As Integer
            Return CType(DataProvider.Instance().AddNewsletter(NLSummary, NLBody, NLDesc, NLAttachment, NLRoleSent, NLUserID, NLEmail, ModuleID, ArticleID, ArticleTabModuleID, Published, PublishDate, PortalID), Integer)
        End Function
        Public Sub UpdateNewsletter(ByVal NLID As Integer, ByVal NLSummary As String, ByVal NLBody As String, ByVal NLDesc As String, ByVal NLAttachment As String, ByVal NLRoleSent As Integer, ByVal NLUserID As Integer, ByVal NLEmail As String, ByVal ModuleID As Integer, ByVal ArticleID As Integer, ByVal ArticleTabModuleID As Integer, ByVal Published As Boolean, ByVal PublishDate As DateTime)
            DataProvider.Instance().UpdateNewsletter(NLID, NLSummary, NLBody, NLDesc, NLAttachment, NLRoleSent, NLUserID, NLEmail, ModuleID, ArticleID, ArticleTabModuleID, Published, PublishDate)
        End Sub
        Public Sub DeleteNewsletter(ByVal NLID As Integer)
            DataProvider.Instance().DeleteNewsletter(NLID)
        End Sub
    End Class
#End Region

#Region "NewsletterTemplateController Class "
    Public Class NewsletterTemplateController
        Public Function GetNewsletterTemplates(ByVal PortalID As Integer) As ArrayList
            Return CBO.FillCollection(DataProvider.Instance().GetNewsletterTemplates(PortalID), GetType(NewsletterTemplateInfo))
        End Function
        Public Function GetNewsletterTemplatebyID(ByVal TLID As Integer) As NewsletterTemplateInfo
            Return CType(CBO.FillObject(DataProvider.Instance().GetNewsletterTemplateById(TLID), GetType(NewsletterTemplateInfo)), NewsletterTemplateInfo)
        End Function
        Public Function AddNewsletterTemplate(ByVal TLBody As String, ByVal TLName As String, ByVal PortalID As Integer) As Integer
            Return CType(DataProvider.Instance().AddNewsletterTemplate(TLBody, TLName, PortalID), Integer)
        End Function
        Public Sub UpdateNewsletterTemplate(ByVal TLBody As String, ByVal TLID As Integer, ByVal PortalID As Integer)
            DataProvider.Instance().UpdateNewsletterTemplate(TLBody, TLID, PortalID)
        End Sub
        Public Sub DeleteNewsletterTemplate(ByVal TLID As Integer)
            DataProvider.Instance().DeleteNewsletterTemplate(TLID)
        End Sub
    End Class
#End Region

#Region "NewsletterUserController Class "
    Public Class NewsletterUserController
        Public Function AddNewsletterUser(ByVal NLID As Integer, ByVal UserID As Integer, ByVal Ignore As Boolean, ByVal Sent As Boolean, ByVal UserEmail As String, ByVal NewsletterCategoryID As Integer, ByVal PublishDate As DateTime, ByVal PortalAliasID As Integer) As Integer
            Return CType(DataProvider.Instance().AddNewsletterUser(NLID, UserID, Ignore, Sent, UserEmail, NewsletterCategoryID, PublishDate, PortalAliasID), Integer)
        End Function
        Public Sub UpdateNewsletterUser(ByVal NLID As Integer, ByVal UserID As Integer, ByVal Ignore As Boolean, ByVal Sent As Boolean, ByVal PublishDate As DateTime)
            DataProvider.Instance().UpdateNewsletterUser(NLID, UserID, Ignore, Sent, PublishDate)
        End Sub
        Public Function GetNewsletterUserUnsent() As ArrayList
            Return CBO.FillCollection(DataProvider.Instance().GetNewsletterUserUnsent(), GetType(NewsletterUserInfo))
        End Function
    End Class
#End Region

#Region "NewsletterCategoryController Class "
    Public Class NewsletterCategoryController
        Public Function AddNewsletterCategory(ByVal NewsletterID As Integer, ByVal CategoryID As Integer) As Integer
            Return CType(DataProvider.Instance().AddNewsletterCategory(NewsletterID, CategoryID), Integer)
        End Function
        Public Function GetNewsletterCategorysByNewsletterID(ByVal NewsletterID As Integer) As ArrayList
            Return CBO.FillCollection(DataProvider.Instance().GetNewsletterCategorysByNewsletterID(NewsletterID), GetType(NewsletterCategoryInfo))
        End Function
        Public Function GetNewsletterCategoryByNewsletterIDCategoryID(ByVal NewsletterID As Integer, ByVal CategoryID As Integer) As NewsletterCategoryInfo
            Return CType(CBO.FillObject(DataProvider.Instance().GetNewsletterCategoryByNewsletterIDCategoryID(NewsletterID, CategoryID), GetType(NewsletterCategoryInfo)), NewsletterCategoryInfo)
        End Function
        Public Sub DeleteNewsletterCategory(ByVal NewsletterID As Integer, ByVal CategoryID As Integer)
            DataProvider.Instance().DeleteNewsletterCategory(NewsletterID, CategoryID)
        End Sub
    End Class
#End Region

#Region "VentrianNAController Class "
    Public Class VentrianNAController
        Public Sub UpdateVentrianNAImages(ByVal ArticleID As Integer)
            DataProvider.Instance().UpdateVentrianNAImages(ArticleID)
        End Sub

    End Class
#End Region
End Namespace
